﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Text;
using System.Collections;
using System.Data.OleDb;
using System.Data;

namespace FDeal
{
    public class LoaiDealDAO : DataProvider
    {
        public LoaiDealDAO()
        { 
        }

        public LoaiDealDTO[] getDsLoaiDeal()
        {
            connect();
            string query = "SELECT * FROM LOAIDEAL";
            adapter = new OleDbDataAdapter(query, connection);
            DataSet dataset = new DataSet();
            adapter.Fill(dataset);
            LoaiDealDTO[] arr;

            DataTable dt = dataset.Tables[0];
            int i, n = dt.Rows.Count;
            arr = new LoaiDealDTO[n];
            for (i = 0; i < n; i++)
            {
                object lop = GetDataFromDataRow(dt, i);
                arr[i] = (LoaiDealDTO)lop;
            }
            return arr;
        }



        protected override object GetDataFromDataRow(DataTable dt, int i)
        {
            LoaiDealDTO ld = new LoaiDealDTO();
            ld.Idhinhthuc = dt.Rows[i]["IDHINHTHUC"].ToString();
            ld.Idloaideal = dt.Rows[i]["IDLOAIDEAL"].ToString();
            ld.Tenloai = dt.Rows[i]["TENLOAI"].ToString();
           

            return (object)ld;
        }

        public void insert(LoaiDealDTO info)
        {
            string insertCommand = "INSERT INTO LOAIDEAL VALUES ('" +
                info.Idhinhthuc + "','" +
                info.Idloaideal + "','" +
                info.Tenloai + "')";


            executeNonQuery(insertCommand);
        }

        public void update(LoaiDealDTO info)
        {
            string updateCommand = "UPDATE LOAIDEAL " +
                                    "SET IDLOAIDEAL = '" + info.Idloaideal + "', " +
                                    " TENLOAI = '" + info.Tenloai + "'," +

                                    " WHERE IDHINHTHUC  = '" + info.Idhinhthuc + "'";

            executeNonQuery(updateCommand);
        }

        public void delete(string idht)
        {
            string deleteCommand = "DELETE FROM LOAIDEAL WHERE IDHINHTHUC = '" + idht + "'";
            executeNonQuery(deleteCommand);
        }
    }
}